package me.imvc.generate.template;

import java.util.*;

public class ControllerTemplate
{
  protected static String nl;
  public static synchronized ControllerTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    ControllerTemplate result = new ControllerTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package me.imvc.app.controllers";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import me.imvc.app.models.";
  protected final String TEXT_3 = ";" + NL + "import me.imvc.core.BaseController;" + NL + "" + NL + "public class ";
  protected final String TEXT_4 = " extends BaseController {" + NL + "" + NL + "\t/**" + NL + "\t * " + NL + "\t */" + NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "\t" + NL + "\tprivate ";
  protected final String TEXT_5 = " ";
  protected final String TEXT_6 = ";" + NL + "" + NL + "\tpublic ";
  protected final String TEXT_7 = " get";
  protected final String TEXT_8 = "() {" + NL + "\t\treturn ";
  protected final String TEXT_9 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
  protected final String TEXT_10 = "(";
  protected final String TEXT_11 = " ";
  protected final String TEXT_12 = ") {" + NL + "\t\tthis.";
  protected final String TEXT_13 = " = ";
  protected final String TEXT_14 = ";" + NL + "\t}" + NL + "\t" + NL + "\tpublic String search(){" + NL + "\t\tget";
  protected final String TEXT_15 = "().searchData();" + NL + "\t\tsetModel(get";
  protected final String TEXT_16 = "().getExcel());" + NL + "\t\treturn render(\"";
  protected final String TEXT_17 = "/search\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String index() {" + NL + "\t\tget";
  protected final String TEXT_18 = "().getPageData(\"Notices\");" + NL + "\t\tsetModel(get";
  protected final String TEXT_19 = "().getExcel());" + NL + "\t\treturn render(\"/";
  protected final String TEXT_20 = "/index\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String show() {" + NL + "\t\tget";
  protected final String TEXT_21 = "().get(getId());" + NL + "\t\treturn render(\"/";
  protected final String TEXT_22 = "/show\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String editNew() {" + NL + "\t\treturn render(\"/";
  protected final String TEXT_23 = "/editNew\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String create() {" + NL + "\t\tget";
  protected final String TEXT_24 = "().save();" + NL + "\t\treturn successMsg(\"创建成功\",\"";
  protected final String TEXT_25 = "\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String edit() {" + NL + "\t\tget";
  protected final String TEXT_26 = "().get(getId());" + NL + "\t\treturn render(\"/";
  protected final String TEXT_27 = "/edit\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String update() {" + NL + "\t\tget";
  protected final String TEXT_28 = "().update(getId());" + NL + "\t\treturn successMsg(\"修改成功\",\"";
  protected final String TEXT_29 = "\");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic String destroy() {" + NL + "\t\tget";
  protected final String TEXT_30 = "().delete(getId());" + NL + "\t\treturn successMsg(\"删除成功\",\"";
  protected final String TEXT_31 = "\");" + NL + "\t}" + NL + "" + NL + "}";
  protected final String TEXT_32 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
Map<String,Object> dataMap=(Map<String,Object>) argument;
LinkedHashMap<String, String> entityAttributMap=(LinkedHashMap<String, String>)dataMap.get("entityAttributMap");
String entityClass=dataMap.get("entityClass").toString();
String entityName=dataMap.get("entityName").toString();
String EntityName=me.imvc.lib.StringTools.firstToUpperCase(entityName);
String modelClass=dataMap.get("modelClass").toString();
String modelName=dataMap.get("modelName").toString();
String ModelName=me.imvc.lib.StringTools.firstToUpperCase(modelName);
String controllerPackage=dataMap.get("controllerPackage").toString();
String controllerClass=dataMap.get("controllerClass").toString();
String view=dataMap.get("view").toString();

    stringBuffer.append(TEXT_1);
    stringBuffer.append(controllerPackage);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(modelClass);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(controllerClass);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(modelClass);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(modelName);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(modelClass);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_8);
    stringBuffer.append(modelName);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(modelClass);
    stringBuffer.append(TEXT_11);
    stringBuffer.append(modelName);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(modelName);
    stringBuffer.append(TEXT_13);
    stringBuffer.append(modelName);
    stringBuffer.append(TEXT_14);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_15);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_16);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_17);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_18);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_19);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_20);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_21);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_22);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_23);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_24);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_25);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_26);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_27);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_28);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_29);
    stringBuffer.append(ModelName);
    stringBuffer.append(TEXT_30);
    stringBuffer.append(view);
    stringBuffer.append(TEXT_31);
    stringBuffer.append(TEXT_32);
    return stringBuffer.toString();
  }
}
